####### Compiler, tools and options

CC            = gcc
CXX           = g++
DEFINES       = -Wall -g -std=c++0x
#DEFINES       = -g -DDEBUG 
CFLAGS        = -O2 $(DEFINES)
CXXFLAGS        = -O2 $(DEFINES)
#CXXFLAGS 	  = -Wall $(DEFINES)
#CXXFLAGS 	  = $(DEFINES)
INCPATH       = -Iinclude 
#INCPATH       = -Iinclude -I/home/feng/include 
LINK          = g++
LFLAGS        = -Wl,--as-needed -Wl,-O1
LIBS          =  
DEL_FILE      = rm -f
DEL_DIR       = rmdir
MOVE          = mv -f

####### Output directory

OBJECTS_DIR   = ./obj

BIN_DIR       = ./bin

####### Files

SOURCES       = example/test/dynamic_test1.cc \
		example/test/dynamic_test2.cc \
		example/test/dynamic_test3.cc \
		example/test/static_test1.cc \
		example/test/static_test2.cc \
		example/test/lu_test.cc \
		example/test/multiply_test.cc \
		example/test/binomial_test.cc \
		example/test/uniform_test.cc \
		example/test/dynamic_multiply.cc 
#example/test/test1.cc 
OBJECTS       = dynamic_test1.o \
		dynamic_test2.o \
		dynamic_test3.o \
		static_test1.o \
		static_test2.o \
		lu_test.o \
		multiply_test.o \
		dynamic_range_test.o \
		binomial_test.o \
		uniform_test.o \
		dynamic_multiply.o 
#test1.o
TARGET        = dynamic_test1 \
		dynamic_test2 \
		dynamic_test3 \
		static_test1 \
		static_test2 \
		lu_test \
		multiply_test \
        binomial_test \
		dynamic_range_test \
		dynamic_multiply
#test1

first: all
####### Implicit rules

.SUFFIXES: .o .c .cpp .cc .cxx .C

.cpp.o:
	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"

.cc.o:
	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"

.cxx.o:
	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"

.C.o:
	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"

.c.o:
	$(CC) -c $(CFLAGS) $(INCPATH) -o "$@" "$<"

####### Build rules

all:  $(TARGET)

$(TARGET):  $(OBJECTS)  
#	$(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS)

####### Detailed Build Rules
dynamic_test1: dynamic_test1.o 
	$(LINK) $(LFLAGS) -o $(BIN_DIR)/dynamic_test1 $(OBJECTS_DIR)/dynamic_test1.o $(OBJCOMP) $(LIBS)

dynamic_test2: dynamic_test2.o 
	$(LINK) $(LFLAGS) -o $(BIN_DIR)/dynamic_test2 $(OBJECTS_DIR)/dynamic_test2.o $(OBJCOMP) $(LIBS)

dynamic_test3: dynamic_test3.o 
	$(LINK) $(LFLAGS) -o $(BIN_DIR)/dynamic_test3 $(OBJECTS_DIR)/dynamic_test3.o $(OBJCOMP) $(LIBS)

static_test1: static_test1.o 
	$(LINK) $(LFLAGS) -o $(BIN_DIR)/static_test1 $(OBJECTS_DIR)/static_test1.o $(OBJCOMP) $(LIBS)

static_test2: static_test2.o 
	$(LINK) $(LFLAGS) -o $(BIN_DIR)/static_test2 $(OBJECTS_DIR)/static_test2.o $(OBJCOMP) $(LIBS)

lu_test: lu_test.o 
	$(LINK) $(LFLAGS) -o $(BIN_DIR)/lu_test $(OBJECTS_DIR)/lu_test.o $(OBJCOMP) $(LIBS)

multiply_test: multiply_test.o 
	$(LINK) $(LFLAGS) -o $(BIN_DIR)/multiply_test $(OBJECTS_DIR)/multiply_test.o $(OBJCOMP) $(LIBS)

dynamic_range_test: dynamic_range_test.o 
	$(LINK) $(LFLAGS) -o $(BIN_DIR)/dynamic_range_test $(OBJECTS_DIR)/dynamic_range_test.o $(OBJCOMP) $(LIBS)

dynamic_multiply: dynamic_multiply.o 
	$(LINK) $(LFLAGS) -o $(BIN_DIR)/dynamic_multiply $(OBJECTS_DIR)/dynamic_multiply.o $(OBJCOMP) $(LIBS)

binomial_test: binomial_test.o 
	$(LINK) $(LFLAGS) -o $(BIN_DIR)/binomial_test $(OBJECTS_DIR)/binomial_test.o $(OBJCOMP) $(LIBS)

uniform_test: uniform_test.o 
	$(LINK) $(LFLAGS) -o $(BIN_DIR)/uniform_test $(OBJECTS_DIR)/uniform_test.o $(OBJCOMP) $(LIBS)
#test1: test1.o 
#	$(LINK) $(LFLAGS) -o $(BIN_DIR)/test1 $(OBJECTS_DIR)/test1.o $(OBJCOMP) $(LIBS)


clean: 
	-$(DEL_FILE) $(OBJECTS_DIR)/*.o
	-$(DEL_FILE) *~ core *.core


####### Sub-libraries

distclean: clean
	-$(DEL_FILE) $(BIN_DIR)/* 


####### Compile

dynamic_test1.o: example/test/dynamic_test1.cc include/matrix.hpp \
		include/matrix/dynamic_matrix.hpp \
		include/matrix/dynamic_matrix/dynamic_matrix_impl.hpp \
		include/matrix/dynamic_matrix/dynamic_matrix_buffer.hpp \
		include/matrix/dynamic_matrix/dynamic_matrix_buffer_0.hpp \
		include/matrix/dynamic_matrix/dynamic_matrix_stride_iterator.hpp \
		include/matrix/static_matrix.hpp \
		include/matrix/static_matrix/static_matrix_m_n.hpp \
		include/matrix/static_matrix/static_matrix_buffer.hpp \
		include/matrix/static_matrix/static_matrix_stride_iterator.hpp \
		include/matrix/static_matrix/static_matrix_m_m.hpp \
		include/matrix/static_matrix/static_matrix_m_1.hpp \
		include/matrix/static_matrix/static_matrix_1_n.hpp \
		include/matrix/static_matrix/static_matrix_1_1.hpp \
		include/matrix/static_matrix/static_matrix_0_0.hpp \
		include/matrix/static_matrix/static_matrix_misc.hpp
	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $(OBJECTS_DIR)/dynamic_test1.o example/test/dynamic_test1.cc

dynamic_test2.o: example/test/dynamic_test2.cc include/matrix.hpp \
		include/matrix/dynamic_matrix.hpp \
		include/matrix/dynamic_matrix/dynamic_matrix_impl.hpp \
		include/matrix/dynamic_matrix/dynamic_matrix_buffer.hpp \
		include/matrix/dynamic_matrix/dynamic_matrix_buffer_0.hpp \
		include/matrix/dynamic_matrix/dynamic_matrix_stride_iterator.hpp \
		include/matrix/static_matrix.hpp \
		include/matrix/static_matrix/static_matrix_m_n.hpp \
		include/matrix/static_matrix/static_matrix_buffer.hpp \
		include/matrix/static_matrix/static_matrix_stride_iterator.hpp \
		include/matrix/static_matrix/static_matrix_m_m.hpp \
		include/matrix/static_matrix/static_matrix_m_1.hpp \
		include/matrix/static_matrix/static_matrix_1_n.hpp \
		include/matrix/static_matrix/static_matrix_1_1.hpp \
		include/matrix/static_matrix/static_matrix_0_0.hpp \
		include/matrix/static_matrix/static_matrix_misc.hpp
	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $(OBJECTS_DIR)/dynamic_test2.o example/test/dynamic_test2.cc

dynamic_test3.o: example/test/dynamic_test3.cc include/matrix.hpp \
		include/matrix/dynamic_matrix.hpp \
		include/matrix/dynamic_matrix/dynamic_matrix_impl.hpp \
		include/matrix/dynamic_matrix/dynamic_matrix_buffer.hpp \
		include/matrix/dynamic_matrix/dynamic_matrix_buffer_0.hpp \
		include/matrix/dynamic_matrix/dynamic_matrix_stride_iterator.hpp \
		include/matrix/static_matrix.hpp \
		include/matrix/static_matrix/static_matrix_m_n.hpp \
		include/matrix/static_matrix/static_matrix_buffer.hpp \
		include/matrix/static_matrix/static_matrix_stride_iterator.hpp \
		include/matrix/static_matrix/static_matrix_m_m.hpp \
		include/matrix/static_matrix/static_matrix_m_1.hpp \
		include/matrix/static_matrix/static_matrix_1_n.hpp \
		include/matrix/static_matrix/static_matrix_1_1.hpp \
		include/matrix/static_matrix/static_matrix_0_0.hpp \
		include/matrix/static_matrix/static_matrix_misc.hpp
	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $(OBJECTS_DIR)/dynamic_test3.o example/test/dynamic_test3.cc

static_test1.o: example/test/static_test1.cc include/matrix.hpp \
		include/matrix/dynamic_matrix.hpp \
		include/matrix/dynamic_matrix/dynamic_matrix_impl.hpp \
		include/matrix/dynamic_matrix/dynamic_matrix_buffer.hpp \
		include/matrix/dynamic_matrix/dynamic_matrix_buffer_0.hpp \
		include/matrix/dynamic_matrix/dynamic_matrix_stride_iterator.hpp \
		include/matrix/static_matrix.hpp \
		include/matrix/static_matrix/static_matrix_m_n.hpp \
		include/matrix/static_matrix/static_matrix_buffer.hpp \
		include/matrix/static_matrix/static_matrix_stride_iterator.hpp \
		include/matrix/static_matrix/static_matrix_m_m.hpp \
		include/matrix/static_matrix/static_matrix_m_1.hpp \
		include/matrix/static_matrix/static_matrix_1_n.hpp \
		include/matrix/static_matrix/static_matrix_1_1.hpp \
		include/matrix/static_matrix/static_matrix_0_0.hpp \
		include/matrix/static_matrix/static_matrix_misc.hpp
	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $(OBJECTS_DIR)/static_test1.o example/test/static_test1.cc

static_test2.o: example/test/static_test2.cc include/matrix.hpp \
		include/matrix/dynamic_matrix.hpp \
		include/matrix/dynamic_matrix/dynamic_matrix_impl.hpp \
		include/matrix/dynamic_matrix/dynamic_matrix_buffer.hpp \
		include/matrix/dynamic_matrix/dynamic_matrix_buffer_0.hpp \
		include/matrix/dynamic_matrix/dynamic_matrix_stride_iterator.hpp \
		include/matrix/static_matrix.hpp \
		include/matrix/static_matrix/static_matrix_m_n.hpp \
		include/matrix/static_matrix/static_matrix_buffer.hpp \
		include/matrix/static_matrix/static_matrix_stride_iterator.hpp \
		include/matrix/static_matrix/static_matrix_m_m.hpp \
		include/matrix/static_matrix/static_matrix_m_1.hpp \
		include/matrix/static_matrix/static_matrix_1_n.hpp \
		include/matrix/static_matrix/static_matrix_1_1.hpp \
		include/matrix/static_matrix/static_matrix_0_0.hpp \
		include/matrix/static_matrix/static_matrix_misc.hpp
	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $(OBJECTS_DIR)/static_test2.o example/test/static_test2.cc

test1.o: example/test/test1.cc include/matrix.hpp \
		include/matrix/dynamic_matrix.hpp \
		include/matrix/dynamic_matrix/dynamic_matrix_impl.hpp \
		include/matrix/dynamic_matrix/dynamic_matrix_buffer.hpp \
		include/matrix/dynamic_matrix/dynamic_matrix_buffer_0.hpp \
		include/matrix/dynamic_matrix/dynamic_matrix_stride_iterator.hpp \
		include/matrix/static_matrix.hpp \
		include/matrix/static_matrix/static_matrix_m_n.hpp \
		include/matrix/static_matrix/static_matrix_buffer.hpp \
		include/matrix/static_matrix/static_matrix_stride_iterator.hpp \
		include/matrix/static_matrix/static_matrix_m_m.hpp \
		include/matrix/static_matrix/static_matrix_m_1.hpp \
		include/matrix/static_matrix/static_matrix_1_n.hpp \
		include/matrix/static_matrix/static_matrix_1_1.hpp \
		include/matrix/static_matrix/static_matrix_0_0.hpp \
		include/matrix/static_matrix/static_matrix_misc.hpp
	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $(OBJECTS_DIR)/test1.o example/test/test1.cc

lu_test.o : include/matrix/matrix_numerical_algorithm/lu_decomposition.hpp example/test/lu_test.cc
	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $(OBJECTS_DIR)/lu_test.o example/test/lu_test.cc


multiply_test.o : example/test/multiply_test.cc include/matrix.hpp 
	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $(OBJECTS_DIR)/multiply_test.o example/test/multiply_test.cc

dynamic_range_test.o : example/test/dynamic_range_test.cc include/matrix.hpp 
	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $(OBJECTS_DIR)/dynamic_range_test.o example/test/dynamic_range_test.cc

dynamic_multiply.o : example/test/dynamic_multiply.cc include/matrix.hpp 
	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $(OBJECTS_DIR)/dynamic_multiply.o example/test/dynamic_multiply.cc

binomial_test.o : example/test/binomial_test.cc
	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $(OBJECTS_DIR)/binomial_test.o example/test/binomial_test.cc

uniform_test.o : example/test/uniform_test.cc
	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $(OBJECTS_DIR)/uniform_test.o example/test/uniform_test.cc

####### Install

